package com.zhoug.androidlibapp;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.zhoug.androidlib.adapter.recycler.BaseRecyclerViewAdapter;
import com.zhoug.androidlib.adapter.recycler.BaseViewHolder;
import com.zhoug.androidlib.adapter.recycler.dividers.ListItemDecoration;
import com.zhoug.androidlib.base.AbsActivity;
import com.zhoug.androidlib.beans.LocalMedia;
import com.zhoug.androidlib.beans.ZFile;
import com.zhoug.androidlib.file.looker.FilePreview;
import com.zhoug.androidlib.file.selector.FileSelectorDialog;
import com.zhoug.androidlib.widget.dialog.gender.GenderChooser;
import com.zhoug.androidlib.widget.dialog.gender.IGenderChooser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FileActivity extends AbsActivity {
    private static final String TAG = ">>>FileActivity";
    private Button mBtnSelector;
    private FilePreview mFilePreview;
    private FileSelectorDialog fileSelectorDialog;

    @Override
    protected void setStatusBar() {
//        super.setStatusBar();
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_file;
    }

    @Override
    protected void findViews() {
        mBtnSelector = findViewById(R.id.btn_selector);
        mFilePreview = findViewById(R.id.file_preview);
        mFilePreview.setDeleteEnable(true);
    }

    @Override
    protected void addListener() {
        mBtnSelector.setOnClickListener(v->{
            if(fileSelectorDialog==null){
                fileSelectorDialog=new FileSelectorDialog(this);
                fileSelectorDialog.addFlag(FileSelectorDialog.FLAG_ALL);
                FileSelectorDialog.ChooseConfig chooseConfig=new FileSelectorDialog.ChooseConfig();
                chooseConfig.captureVideo=true;
                chooseConfig.captureImage=true;
                chooseConfig.maxDuration=1000*60;
                chooseConfig.minDuration=1000;
                chooseConfig.maxNum=5;
                fileSelectorDialog.setChooseConfig(chooseConfig);
                fileSelectorDialog.setOnSelectListener(medias -> {
                    if(medias!=null && medias.size()>0){
                        List<ZFile> files=new ArrayList<>();
                        for(LocalMedia localMedia:medias){
                            files.add(new ZFile(localMedia.getPath(),localMedia.getFileType() ));
                        }
                        mFilePreview.addAllFile(files);
                    }
                });
            }
            fileSelectorDialog.show();
        });
    }

    @Override
    protected void onCreateFinish(@Nullable Bundle savedInstanceState) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(null!=fileSelectorDialog){
            fileSelectorDialog.onActivityResult(requestCode, resultCode, data);
        }
    }
}
